<?php

class FileController extends Base {

	public function uploadAction()
	{
		$file = $this->getRequest()->getFiles('file');
		if ($file) {
	        $file_path = 'upload/'.date('Ym').'/';//设置文件路径
	        $blob_num =  $this->getRequest()->getPost('chunk');//当前片数
	        $total_num = $this->getRequest()->getPost('chunks');//总片数
	        $file_name = $this->getRequest()->getPost('name');//文件名称
	        $temp_name = $file['tmp_name'];//零时文件名称
	        // dd(compact('file_name','temp_name'));
	        $uploadClass = new Upload($file_path, $blob_num, $total_num, $file_name, $temp_name);//实例化upload类，并传入相关参数
	        $server = $this->getRequest()->getServer();
	        $data = $uploadClass->apiReturn($server);
	        echo json_encode($data);die();
	    } else {
	        $data['code'] = 0;
	        $data['msg'] = 'error code:' . $_FILES['file']['error'];
	        $data['file_path'] = '';
	        echo json_encode($data);die();
	    }
	}

}